import 'package:easy_read_comic/internal/http_client.dart';
import 'package:dio/dio.dart';

class ComicApi {
  // 静态变量来保存唯一的实例
  static final ComicApi _instance = ComicApi._internal();

  // 私有构造函数
  ComicApi._internal();

  // 工厂构造函数
  factory ComicApi() {
    return _instance;
  }

  // resourceList 获取资源列表
  Future<Response> resourceList(String chapterId) async {
    return HttpClient().get("/v1/comic/resource_list/$chapterId");
  }

  // detail  漫画详情
  Future<Response> detail(String comicId) async {
    return HttpClient().get("/v1/comic/detail/$comicId");
  }

  // chapterList  漫画章节查询
  Future<Response> chapterList(String comicId, {int currentPage = 0}) async {
    return HttpClient()
        .get("/v1/comic/chapter_list/$comicId", queryParameters: {
      "page": currentPage,
    });
  }

  // list 漫画列表
  Future<Response> list(
      {String? title = null,
      int? navigateId = null,
      int currentPage = 0}) async {
    Map<String, dynamic> query = {
      "page": currentPage,
    };
    if (navigateId != null) {
      query["navigate_id"] = navigateId;
    }
    if (title != null) {
      query["title"] = title;
    }
    return HttpClient().get("/v1/comic/list", queryParameters: query);
  }

  // hotSearch 热门搜索
  Future<Response> hotSearch() async {
    return HttpClient().get("/v1/comic/hot_search");
  }

  // chapterDetail 章节详情
  Future<Response> chapterDetail(String chapterId) async {
    return HttpClient().get("/v1/comic/chapter_detail/$chapterId");
  }

  // comicLookFor 帮找漫画
  Future<Response> comicLookFor(String title, {String? link = null}) async {
    return HttpClient().post(
      "/v1/comic/comic_look_for",
      data: {
        "title": title,
        "link": link,
      },
    );
  }
}
